package com.stu.exercise.entity;

import lombok.Data;
import lombok.ToString;

@Data
@ToString
public class R<T> {

    private int status;       // 状态码
    private String message;   // 消息
    private T data;           // 数据

    public R() {
    }

    public R(int status, String message, T data) {
        this.status = status;
        this.message = message;
        this.data = data;
    }

    // 成功返回
    public static <T> R<T> success(T data) {
        return new R<>(200, "Success", data);
    }

    public static <T> R<T> success(String message, T data) {
        return new R<>(200, message, data);
    }

    // 错误返回
    public static <T> R<T> error(int status, String message) {
        return new R<>(status, message, null);
    }

    // 自定义返回
    public static <T> R<T> custom(int status, String message, T data) {
        return new R<>(status, message, data);
    }

    // Getters and Setters
    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}

